package com.esri.android.map.popup;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;

/* loaded from: classes.dex */
public class ArcGISMediaView extends ArcGISAbstractMediaView implements PopupEditable, PopupRefreshable {
    protected ArcGISMediaAdapter mMediaAdapter;

    public ArcGISMediaView(Context context, Popup popup) {
        super(context, popup, "Media");
        this.mMediaAdapter = new ArcGISMediaAdapter(context, this.a);
        this.mGrid.setAdapter((ListAdapter) this.mMediaAdapter);
        this.mGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() { // from class: com.esri.android.map.popup.ArcGISMediaView.1
            @Override // android.widget.AdapterView.OnItemClickListener
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
                ArcGISMediaFullScreenView arcGISMediaFullScreenView = new ArcGISMediaFullScreenView(ArcGISMediaView.this.getContext(), ArcGISMediaView.this.mMediaAdapter, i);
                Dialog dialog = new Dialog(ArcGISMediaView.this.getContext(), 16973826);
                dialog.requestWindowFeature(1);
                dialog.setContentView(arcGISMediaFullScreenView, new LinearLayout.LayoutParams(-1, -1));
                dialog.show();
            }
        });
        refresh();
    }

    @Override // com.esri.android.map.popup.PopupRefreshable
    public void refresh() {
        ArcGISMediaAdapter arcGISMediaAdapter = this.mMediaAdapter;
        if (arcGISMediaAdapter == null || arcGISMediaAdapter.getCount() < 1) {
            setVisibility(8);
        } else {
            this.mGrid.postInvalidate();
        }
    }

    @Override // com.esri.android.map.popup.PopupEditable
    public void setEditMode(boolean z) {
        ArcGISMediaAdapter arcGISMediaAdapter = this.mMediaAdapter;
        if (arcGISMediaAdapter == null || arcGISMediaAdapter.getCount() <= 0) {
            return;
        }
        setVisibility(z ? 8 : 0);
    }

    public ArcGISMediaAdapter getMediaAdapter() {
        return this.mMediaAdapter;
    }

    public void setMediaAdapter(ArcGISMediaAdapter arcGISMediaAdapter) {
        this.mMediaAdapter = arcGISMediaAdapter;
        refresh();
    }

    @Override // android.widget.LinearLayout, android.view.View
    protected void onMeasure(int i, int i2) {
        super.onMeasure(i, i2);
        ArcGISMediaAdapter arcGISMediaAdapter = this.mMediaAdapter;
        if (arcGISMediaAdapter != null) {
            arcGISMediaAdapter.setColumnWidth(this.mAdjustedColumnWidth);
        }
    }

    @Override // android.view.View
    public void setVisibility(int i) {
        ArcGISMediaAdapter arcGISMediaAdapter;
        if (i != 0 || ((arcGISMediaAdapter = this.mMediaAdapter) != null && arcGISMediaAdapter.getCount() >= 1)) {
            super.setVisibility(i);
        }
    }
}
